<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopGoodsTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_goods', ['comment' => '商品', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('title', 'string', ['limit'  =>  255, 'default' => '', 'comment' => '标题'])
            ->addColumn('subtitle', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '副标题'])
            ->addColumn('category_ids', 'string', ['limit'  =>  120, 'null' => true, 'default' => null, 'comment' => '所属分类'])
            ->addColumn('image', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '商品主图'])
            ->addColumn('images', 'string', ['limit'  =>  2500, 'null' => true, 'default' => null, 'comment' => '轮播图'])
            ->addColumn('params', 'string', ['limit'  =>  2500, 'null' => true, 'default' => null, 'comment' => '参数详情'])
            ->addColumn('content', 'text', ['null' => true, 'default' => null, 'comment' => '图文详情'])
            ->addColumn('original_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '原价'])
            ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '价格'])
            ->addColumn(Column::tinyInteger('is_sku')->setDefault(0)->setUnsigned()->setComment('是否多规格'))
            ->addColumn(Column::enum('limit_type', ['none', 'daily', 'all'])->setDefault('none')->setComment('限购类型:none=不限购,daily=每日,all=累计'))
            ->addColumn('limit_num', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '限购数量'])
            ->addColumn('likes', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '收藏人数'])
            ->addColumn('views', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '浏览人数'])
            ->addColumn('sales', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '销量'])
            ->addColumn(Column::enum('sales_show_type', ['exact', 'sketchy'])->setDefault('exact')->setComment('销量显示类型:exact=精确的,sketchy=粗略的'))
            ->addColumn(Column::enum('stock_show_type', ['exact', 'sketchy'])->setDefault('exact')->setComment('库存显示类型:exact=精确的,sketchy=粗略的'))
            ->addColumn('show_sales', 'integer', ['limit'  => 10, 'default' => 0, 'comment' => '显示销量'])
            ->addColumn('service_ids', 'string', ['limit'  => 120, 'null' => true, 'default' => null, 'comment' => '服务标签'])
            ->addColumn('dispatch_id', 'integer', ['limit'  => 11, 'default' => 0, 'comment' => '发货模板'])
            ->addColumn(Column::enum('status', ['up', 'hidden', 'down'])->setDefault('up')->setComment('商品状态:up=上架,hidden=隐藏,down=下架'))
            ->addColumn('weigh', 'integer', ['limit'  =>  8, 'default' => 0, 'comment' => '权重'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addColumn('delete_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '删除时间'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_goods');
        $table->drop();
    }
}
